﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ActivityTracker;
using ActivityTracker.Library;
using Common.Library;


namespace ActivityTracker
{
    public partial class SetPriority : PhoneApplicationPage
    {
        #region global declaration

        //LoadData LoadData = new LoadData();
        //SaveData SaveData = new SaveData();
        int count = 20;

        #endregion

        #region constructor

        public SetPriority()
        {
            InitializeComponent();
        }

        #endregion

        #region page events

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                string Index = "";
                string Count = "";
                NavigationContext.QueryString.TryGetValue("Index", out Index);
                NavigationContext.QueryString.TryGetValue("Count", out Count);
                count = Convert.ToInt32(Count);
                //List<ActivityProperties> MyActivitieslist = LoadData.LoadMyActivities(count);
                //if (MyActivitieslist.Count < 1)
                //{
                //    popup.IsOpen = true;
                //}
                //ListBoxMyActivities.ItemsSource = MyActivitieslist;
                //ListBoxMyActivities.SelectedIndex = Convert.ToInt32(Index);
            }
            catch (Exception ex)
            {
                string mess = "Exception in PhoneApplicationPage_Loaded Method In SetPriority file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Activities/Activities.xaml", UriKind.Relative));
        }

        private void ListBoxMyActivities_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (ListBoxMyActivities.SelectedIndex != -1)
                {
                    string name = "";
                    name = (ListBoxMyActivities.SelectedItem as ActivityProp).ActName;
                    if (name == "get more acitivities")
                    {
                        count = count + 20;
                        //ListBoxMyActivities.ItemsSource = LoadData.LoadMyActivities(count);
                        //ListBoxMyActivities.ScrollIntoView(ListBoxMyActivities.Items[count - 20]);
                    }
                }
            }
            catch (Exception ex)
            {
                string mess = "Exception in ListBoxMyActivities_SelectionChanged Method In SetPriority file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void ApplicationBarUpButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (ListBoxMyActivities.SelectedIndex > 0)
                {
                    int selindex = ListBoxMyActivities.SelectedIndex;

                    //ActivityProperties Selecteditem = ListBoxMyActivities.SelectedItem as ActivityProperties;
                    //ActivityProperties MovetoItem = ListBoxMyActivities.Items[ListBoxMyActivities.SelectedIndex - 1] as ActivityProperties;
                    //SaveData.Move(Selecteditem.ActivityId.ToString(), MovetoItem.ActivityId.ToString());
                   // ListBoxMyActivities.ItemsSource = LoadData.LoadMyActivities(count);
                    //ListBoxMyActivities.SelectedIndex = selindex - 1;
                }
            }
            catch (Exception ex)
            {
                string mess = "Exception in ApplicationBarUpButton_Click Method In SetPriority file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void ApplicationBarDownButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (ListBoxMyActivities.SelectedIndex < ListBoxMyActivities.Items.Count - 1 && ListBoxMyActivities.SelectedIndex != -1)
                {
                    int selindex = ListBoxMyActivities.SelectedIndex;
                    //ActivityProperties Selecteditem = ListBoxMyActivities.SelectedItem as ActivityProperties;
                    //ActivityProperties MovetoItem = ListBoxMyActivities.Items[ListBoxMyActivities.SelectedIndex + 1] as ActivityProperties;
                    //SaveData.Move(Selecteditem.ActivityId.ToString(), MovetoItem.ActivityId.ToString());
                    //ListBoxMyActivities.ItemsSource = LoadData.LoadMyActivities(count);
                    //ListBoxMyActivities.SelectedIndex = selindex + 1;
                }
            }
            catch (Exception ex)
            {
                string mess = "Exception in ApplicationBarDownButton_Click Method In SetPriority file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        #endregion


    }
}